<template>
  <div>
    <el-card>
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="登录账户设置" name="logInfo">
          <el-form
            :model="userInfo"
            label-width="60px"
            style="width:350px;margin:50px auto;"
            ref="baseForm"
          >
            <el-form-item label="姓名：" prop="username">
              <el-input v-model="userInfo.username"></el-input>
            </el-form-item>
            <el-form-item label="密码：" prop="password">
              <el-input v-model="userInfo.password" type="password"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="saveProfile">更新</el-button>
              <el-button>取消</el-button>
            </el-form-item>
          </el-form>
        </el-tab-pane>

        <!-- 个人详情 -->
        <el-tab-pane label="个人详情" name="userInfo">
          <user-info />
        </el-tab-pane>

        <!-- 岗位信息 -->
        <el-tab-pane label="岗位信息" name="jobInfo">
          <job-info />
        </el-tab-pane>
      </el-tabs>
    </el-card>
  </div>
</template>

<script>
//导入获取头像的接口
import { userProfile } from '@/api/user'
import { saveProfile } from '@/api/yuangong'
import userInfo from './components/user-info.vue'
import JobInfo from './components/job-info.vue'
export default {
  name: 'detail',
  components: {
    userInfo,
    JobInfo
  },
  data () {
    return {
      activeName: 'logInfo',
      form: {},
      userInfo: {},
      rules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ],
        password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
      }
    }
  },
  created () {
    this.getBasProfile()
  },
  methods: {
    async getBasProfile () {
      let res = await userProfile(this.$route.query.id)

      this.userInfo = res.data
    },
    //更新按钮点击事件
    saveProfile () {
      //做表单验证
      this.$refs.baseForm.validate(async v => {
        if (v) {
          // 发起请求
          await saveProfile(this.userInfo)
          this.$message.success('更新成功!')
        }
      })
    },
    handleClick (tab, event) {
      console.log(tab, event)
    }
  }
}
</script>

<style></style>
